﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Net;
using System.IO;
using System.Web.Script.Serialization;
using PiscoSourDominio;
using System.Text; 

namespace PiscoSourWeb.Models
{
    public class ModelCliente : IDisposable
    {

        public IEnumerable<Cliente> ListarClientesInactivos()
        {
            HttpWebRequest req2 = (HttpWebRequest)WebRequest
                    .Create("http://localhost:49781/Services/Clientes.svc/ListaClientesIna");
            req2.Method = "GET";
            HttpWebResponse res2 = (HttpWebResponse)req2.GetResponse();
            StreamReader reader2 = new StreamReader(res2.GetResponseStream());
            string ReservaJson2 = reader2.ReadToEnd();
            JavaScriptSerializer js2 = new JavaScriptSerializer();
            List<Cliente> lista = js2.Deserialize<List<Cliente>>(ReservaJson2);
            return lista;
        }

        public IEnumerable<Cliente> ListarClientes()
        {
            HttpWebRequest req2 = (HttpWebRequest)WebRequest
                    .Create("http://localhost:49781/Services/Clientes.svc/ListaClientes");
            req2.Method = "GET";
            HttpWebResponse res2 = (HttpWebResponse)req2.GetResponse();
            StreamReader reader2 = new StreamReader(res2.GetResponseStream());
            string ReservaJson2 = reader2.ReadToEnd();
            JavaScriptSerializer js2 = new JavaScriptSerializer();
            List<Cliente> lista = js2.Deserialize<List<Cliente>>(ReservaJson2);
            return lista;
        }

        public Cliente ValidarCliente(string vchusuario, string vchpass)
        {
            string strdata = "/" + vchusuario + "/" + vchpass;
            HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create("http://localhost:49781/Services/Clientes.svc/ValidaCliente" + strdata);
            httpReq.Method = "GET";
            httpReq.ContentType = "application/json";

            var Resrp = (HttpWebResponse)httpReq.GetResponse();
            StreamReader strread = new StreamReader(Resrp.GetResponseStream());
            string strJson = strread.ReadToEnd();

            JavaScriptSerializer js = new JavaScriptSerializer();
            Cliente objCliente = js.Deserialize<Cliente>(strJson);

            return objCliente;
            
        }

        public Usuario ObtenerUsuarioCliente(string vchusuario, string vchpass)
        {
            string strdata = "/" + vchusuario + "/" + vchpass;
            HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create("http://localhost:49781/Services/Cliente.svc/UCliente" + strdata);
            httpReq.Method = "POST";
            httpReq.ContentType = "application/json";

            var Resrp = (HttpWebResponse)httpReq.GetResponse();
            StreamReader strread = new StreamReader(Resrp.GetResponseStream());
            string strJson = strread.ReadToEnd();

            JavaScriptSerializer js = new JavaScriptSerializer();
            Usuario objUsuario = js.Deserialize<Usuario>(strJson);

            return objUsuario;

        }

        public void Dispose()
        {
            
        }
 
    }

}